package cn.stylefeng.guns.modular.rest;


import cn.stylefeng.guns.modular.wordstudy.entity.Favorite;
import cn.stylefeng.guns.modular.wordstudy.entity.Word;
import cn.stylefeng.guns.modular.wordstudy.entity.WordTest;
import cn.stylefeng.guns.modular.wordstudy.model.params.StudyHistoryParam;
import cn.stylefeng.guns.modular.wordstudy.model.result.StudyHistoryResult;
import cn.stylefeng.guns.modular.wordstudy.service.FavoriteService;
import cn.stylefeng.guns.modular.wordstudy.service.StudyHistoryService;
import cn.stylefeng.guns.modular.wordstudy.service.WordService;
import cn.stylefeng.guns.modular.wordstudy.service.WordTestService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;


/**
 * 绑定控制器
 *
 * @author
 * @Date 2019-11-18 13:24:11
 */
@RestController
@RequestMapping("/gunsApi/word/test")
public class ApiNeedTokenWordTestController extends BaseController {

    @Autowired
    private WordTestService wordTestService;
    @Autowired
    private WordService wordService;

    @RequestMapping(value = "random")
    public Object random() {
        Map map = new HashMap();

        List<WordTest> words = wordTestService.list();
        Random random = new Random();
        int n = random.nextInt(words.size());
        WordTest wordTest = words.get(n);

        Word word = wordService.getOne(new QueryWrapper<Word>().eq("name", wordTest.getQuestion()));

        map.put("wordTest", wordTest);
        map.put("word", word);

        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

}


